var rpid = _$("#rpid").sgAttr.attr({t:"value"});//获取业务传递过来的rpid
var url = _$("#creditAjaxUrl").sgAttr.attr({t:"value"});//请求动态数据url
var isReSel = _$("#isReSelPayFlag").sgAttr.attr({t:"value"});//是否重新支付标识

var payType = _$("#payType").sgAttr.attr({t:"value"});      //得到银行类型
var binBankId = _$("#binBankId").sgAttr.attr({t:"value"});   //得到binBankId
var creditGateId = _$("#creditGateId").sgAttr.attr({t:"value"});   //得到creditGateId
var merId = _$("#merId").sgAttr.attr({t:"value"});   //得到merId


var isHistory=false,isHisBool=false;
var trace = _$("#trace").sgAttr.attr({t:"value"});
var instId = _$("#instId").sgAttr.attr({t:"value"});
var rpid = _$("#rpid").sgAttr.attr({t:"value"});
var orderId = _$("#orderId").sgAttr.attr({t:"value"});
var orderDate = _$("#orderDate").sgAttr.attr({t:"value"});
var merName = _$("#merName").sgAttr.attr({t:"value"});
var amount = _$("#amount").sgAttr.attr({t:"value"});
var payTypeStr=_$("#payTypeStr").sgAttr.attr({t:"value"}); 
var isPAgreementPay = _$("#isPAgreementPay").sgAttr.attr({t:"value"}); //是否协议支付
var baseProductId = _$("#baseProductId").sgAttr.attr({t:"value"});//基础支付产品号

//只有为非协议支付时，才需要加载各支付要素
if(isPAgreementPay!="Y"){   
        // 单击有效期 隐藏错误提示信息
       _$().each({m:"select.month select.year".split(' '),c:function(){ //有效期取值 2012-03-29edit
           _$(this).change({f:function(){
                   var classArray = this.className.split(' ');
           }});
       }});
       //加载有效期年月
		var mStr = $("#creditMonthsJsonKey").val();//信用卡有效期中的月份列表，目前后台json返回形式为1||1,2||2,3||3,......
		var yStr = $("#creditYearsJsonKey").val();//信用卡有效期中的年列表，目前后台json返回形式为1||1,2||2,3||3,......
		var year = $("#validDateY").val();
		var month = $("#validDateM").val();
		var modifyFlag = $("#modifyFlag").val();
		if("P0050000"==baseProductId){//只有为信用卡时，才加载有效期
		//只有当允许修改时或者没有传入支付要素时，才需要加载
		if (mStr != null&&(month==""||modifyFlag!="0")) {//信用卡月字符串进行解析，动态封装到select中
			var selMonth = mStr.split(",");
			if (selMonth != null) {
				var mLen = selMonth.length - 1;
				for (var i = 0; i < mLen; i++) {
					var obj = selMonth[i];
					if(obj.split("||")[1]==month){//设置信用卡有效期初始值
						doc.getElementById("validDateMV").options.add(new Option(obj.split("||")[1], obj.split("||")[0],true,true));
					}else {
						doc.getElementById("validDateMV").options.add(new Option(obj.split("||")[1], obj.split("||")[0]));
					}
				}
			}
		}
		if (yStr != null&&(year==""||modifyFlag!="0")) {//信用卡年字符串进行解析，动态封装到select中
			var selYear = yStr.split(",");
			if (selYear != null) {
				var yLen = selYear.length - 1;
				for (var i = 0; i < yLen; i++) {
					var obj = selYear[i];
					if(obj.split("||")[1]==year){//设置信用卡有效期初始值
						doc.getElementById("validDateYV").options.add(new Option(obj.split("||")[1], obj.split("||")[0],true,true));
					}else{
						doc.getElementById("validDateYV").options.add(new Option(obj.split("||")[1], obj.split("||")[0]));
					}
				}
			}
		}
		}
		
       //有效期、验证码图列
		  _$().each({m:["seltip","inptip","xyt"],c:function(i){
	           _$("a."+this).each({c:function(){
	               if (i==0){
	            	   _$().showImg(this,"img.monthimg");
	               }
	               if (i==1){
	            	   _$().showImg(this,"img.yzmimg");
	            	   }
	               if (i==2){
	                   _$(this).click({f:function(){
	                        var str = _$("span.xycontent").sgAttr.html();
	                        _$().shortCutalertPro("U付服务用户协议 ",str,"sysAlert",true,function(){
	                            //关闭、TITLE关闭按钮点击后事件
	                        },false,null,"sysAlert");
	                   }});
	               }
	           }});
	       }});
		
     //输入框默认与输入状态切换 --持卡人姓名
       _$().each({m:["input.cardHolder"],c:function(){
         	 _$(this).bind({t:'click focus',f:function(){
	        var old = _$(this).sgAttr.attr({t:"rel"}).trim(),value = _$().sgText.trim({t:this.value,f:"all"}),classArray = this.className.split(' ');
               if(value == old){
                   _$(this).sgAttr.attr({t:"value",v:""}).sgCss.addClass({v:"sel"});
               }
               $("#cardHolderErr").hide();
     	}});
     	_$(this).blur({f:function(){
	        var old = _$(this).sgAttr.attr({t:"rel"}),value = _$().sgText.trim({t:this.value,f:"all"}),classArray = this.className.split(' ');
	        $("#cardHolderErr").hide();
               if (value == ""){
                   _$(this).sgAttr.attr({t:"value",v:old}).sgCss.removeClass({v:"sel"});
               }else if(value !=old && (value.length<2 || value.length>16 || !(_$().checkChinese(value)))){
            	   $("#cardHolderErr").show();
               }
           }});
       }});
       
       //输入框默认与输入状态切换 --CVV2
       _$().each({m:["input.cvv"],c:function(){
         	 _$(this).bind({t:'click focus',f:function(){
	        var old = _$(this).sgAttr.attr({t:"rel"}).trim(),value = _$().sgText.trim({t:this.value,f:"all"}),classArray = this.className.split(' ');
               if(value == old){
                   _$(this).sgAttr.attr({t:"value",v:""}).sgCss.addClass({v:"sel"});
               }
               $("#cvv2Err").hide();
     	}});
     	_$(this).blur({f:function(){
	        var old = _$(this).sgAttr.attr({t:"rel"}),value = _$().sgText.trim({t:this.value,f:"all"}),classArray = this.className.split(' ');
	        $("#cvv2Err").hide();
               if (value == ""){
                   _$(this).sgAttr.attr({t:"value",v:old}).sgCss.removeClass({v:"sel"});
               }else if(value !=old && (value.length!=3||!(checkCVV2(value)))){
            	   $("#cvv2Err").show();
               }
           }});
       }});
       
       //输入框默认与输入状态切换 --身份证号
       _$().each({m:["input.identityCode"],c:function(){
         	 _$(this).bind({t:'click focus',f:function(){
	        var old = _$(this).sgAttr.attr({t:"rel"}).trim(),value = _$().sgText.trim({t:this.value,f:"all"}),classArray = this.className.split(' ');
               if(value == old){
                   _$(this).sgAttr.attr({t:"value",v:""}).sgCss.addClass({v:"sel"});
               }
               $("#identityErr").hide();
               $("#identityEmpty").hide();
     	}});
     	_$(this).blur({f:function(){
	        var old = _$(this).sgAttr.attr({t:"rel"}),value = _$().sgText.trim({t:this.value,f:"all"}),classArray = this.className.split(' ');
	        $("#identityErr").hide();
	        $("#identityEmpty").hide();
               if (value == ""){
                   _$(this).sgAttr.attr({t:"value",v:old}).sgCss.removeClass({v:"sel"});
               }else if(value !=old && (!(checkIdcard(value)))){
            	   $("#identityEmpty").hide();
            	   $("#identityErr").show();
               }
           }});
       }});
       
       //输入框默认与输入状态切换 --卡号
       _$().each({m:["input.cardId"],c:function(){
       	 _$(this).bind({t:'click focus',f:function(){
	        var old = _$(this).sgAttr.attr({t:"rel"}).trim(),value = _$().sgText.trim({t:this.value,f:"all"}),classArray = this.className.split(' ');
             if(value == old){
                 _$(this).sgAttr.attr({t:"value",v:""}).sgCss.addClass({v:"sel"});
             }else{
          	   value =value.replace(/\s/g,'');
          	   _$(this).sgAttr.attr({t:"value",v:value});
             }
             $("#cardErr").hide();
             $("#cardEmpty").hide();
             
   	}});
   	_$(this).blur({f:function(){
	        var old = _$(this).sgAttr.attr({t:"rel"}),value = _$().sgText.trim({t:this.value,f:"all"}),classArray = this.className.split(' ');
	               $("#cardErr").hide();
	               $("#cardEmpty").hide();
             if (value == ""){
                 _$(this).sgAttr.attr({t:"value",v:old}).sgCss.removeClass({v:"sel"});
             }else if(value !=old&&(value.length<15||value.length>19||!(checkCreditCard(value)))){
                     $("#cardErr").show();
                     $("#cardEmpty").hide();
             }else{
          	   value =value.replace(/\s/g,'').replace(/(\d{4})(?=\d)/g,"$1 ");
          	   _$(this).sgAttr.attr({t:"value",v:value});
             }
         }});
     }});
       
       //输入框默认与输入状态切换 --手机号
       _$().each({m:["input.f_mobile"],c:function(){
         	 _$(this).bind({t:'click focus',f:function(){
               var old = _$(this).sgAttr.attr({t:"rel"}).trim(),value = _$().sgText.trim({t:this.value,f:"all"}),className = this.className.split(' ');
               if(value == old) _$(this).sgAttr.attr({t:"value",v:""}).sgCss.addClass({v:"sel"});
               $("#mobileErr").hide();
     	}});
     	_$(this).blur({f:function(){
	         var old = _$(this).sgAttr.attr({t:"rel"}).trim(),value = _$().sgText.trim({t:this.value,f:"all"}),className = this.className,classArray = className.split(' ');
	         $("#mobileErr").hide();
               if (value == ""){
                   _$(this).sgAttr.attr({t:"value",v:old}).sgCss.removeClass({v:"sel"});
               }else  if(value !=old && !(_$().checkMobileId(value))){
                	  $("#mobileErr").show();
               }
           }});
       }});
       
       //输入框默认与输入状态切换 --有效期
       $("select.month,select.year").click(function(){
    	   $("#validDateErr").hide();
       });
       $("select.month,select.year").blur(function(){
    	   var month = doc.getElementById("validDateMV").value, year = doc.getElementById("validDateYV").value;
    	   if(month=="" || year==""){
    	       $("#validDateErr").show();
    	   }else{
    		   $("#validDateErr").hide();
    	   }
       });
       
}
//无论是首次支付还是协议支付，验证码输入框都存在，故默认提示语的消失功能需保留
       _$().each({m:["input.yzm.t_sms","input.yzm.f_sms"],c:function(){  //输入框默认与输入状态切换 --验证码
            _$(this).bind({t:'click focus',f:function(){
               var old = _$(this).sgAttr.attr({t:"rel"}).trim(),value = _$().sgText.trim({t:this.value,f:"all"}),id=this.id.trim();
               if(value == old) _$(this).sgAttr.attr({t:"value",v:""}).sgCss.addClass({v:"sel"});
               $("#verifyCodeErr").hide();
               $("#msgVerifyErr").hide();
            }});
            _$(this).blur({f:function(){
               var old = _$(this).sgAttr.attr({t:"rel"}).trim(),value = _$().sgText.trim({t:this.value,f:"all"}),id=this.id.trim();
               $("#verifyCodeErr").hide();
               $("#msgVerifyErr").hide();
               if (value == ""){
                    _$(this).sgAttr.attr({t:"value",v:old}).sgCss.removeClass({v:"sel"});
               }else{
               	if (value != old && !(_$().checkVerCode(value))) {
               	 $("#verifyCodeErr").show();
               	$("#msgVerifyErr").hide();
               	}
               }
            }});
       }});
       
		_$().each({m:["itip"], c:function () {//安全提示层
				_$().showTip("span." + this, function (obj, w, jt) {  //安全提示层显示
					var top = _$(obj).Top() || 0, left = _$(obj).Left() || 0;
					_$(this).sgCss.css({t:"text", v:"background:#ffffce;width:160px;z-index:9999;display:block;top:-10px;left:" + (w + 15) + "px"});
					_$(jt).sgCss.css({t:"text", v:"top:10px"});
				});
		}});
